package l1j.server.server.clientpackets;

import l1j.opqlo.Server.L1World.L1World;
import l1j.server.echo.ClientThread;
import l1j.server.server.model.L1Object;
import l1j.server.server.model.Instance.L1DummyInstance;
import l1j.server.server.model.Instance.L1PcInstance;
import l1j.server.server.serverpackets.S_PrivateShop;

import java.util.logging.Level;
import java.util.logging.Logger;
// Referenced classes of package l1j.server.server.clientpackets:
// ClientBasePacket

/**
 * 處理收到由客戶端傳來商店清單的封包
 */
public class C_ShopList extends ClientBasePacket {
	private static final Logger _log = Logger.getLogger(C_ShopList.class.getName());
	private static final String C_SHOP_LIST = "[C] C_ShopList";

	@Override
	public String getType() {
		return C_SHOP_LIST;
	}

	@Override
	public void start(final byte[] decrypt, final ClientThread client) {
		try {
			// 資料載入
			this.read(decrypt);

			final L1PcInstance pc = client.getActiveChar();
			if (pc == null || pc.isGhost()) {
				return;
			}

			final int type = this.readC();
			final int objectId = this.readD();
			
			L1Object object = L1World.getInstance().findObject(objectId);
			if (object instanceof L1DummyInstance)
			{
				pc.sendPackets(new S_PrivateShop((L1DummyInstance) object));
				return;
			}
			pc.sendPackets(new S_PrivateShop(pc, objectId, type));
		} catch (final Exception e) {
			_log.log(Level.SEVERE, e.getLocalizedMessage(), e);

		} finally {
			this.over();
		}
	}

}
